package olap4cloud.hadop.statistic;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;

public class Model implements WritableComparable<Model>{

	/**
	 * @uml.property  name="key"
	 */
	private byte[] key;
	/**
	 * @uml.property  name="columF"
	 */
	private byte[] columF;
	/**
	 * @uml.property  name="columQ"
	 */
	private byte[] columQ;
	
	public Model(){}

	public Model(byte[] key, byte[] columF, byte[] columQ) {
		this.key = key;
		this.columF = columF;
		this.columQ = columQ;
	}

	/**
	 * @return
	 * @uml.property  name="key"
	 */
	public byte[] getKey() {
		return key;
	}

	/**
	 * @param key
	 * @uml.property  name="key"
	 */
	public void setKey(byte[] key) {
		this.key = key;
	}

	/**
	 * @return
	 * @uml.property  name="columF"
	 */
	public byte[] getColumF() {
		return columF;
	}

	/**
	 * @param columF
	 * @uml.property  name="columF"
	 */
	public void setColumF(byte[] columF) {
		this.columF = columF;
	}

	/**
	 * @return
	 * @uml.property  name="columQ"
	 */
	public byte[] getColumQ() {
		return columQ;
	}

	/**
	 * @param columQ
	 * @uml.property  name="columQ"
	 */
	public void setColumQ(byte[] columQ) {
		this.columQ = columQ;
	}

	@Override
	public void readFields(DataInput input) throws IOException {
		// TODO Auto-generated method stub
		key = input.readUTF().getBytes();
		columF = input.readUTF().getBytes();
		columQ = input.readUTF().getBytes();
	}

	@Override
	public void write(DataOutput output) throws IOException {
		// TODO Auto-generated method stub
		output.writeUTF(new String(key));
		output.writeUTF(new String(columF));
		output.writeUTF(new String(columQ));
	}

	@Override
	public int compareTo(Model arg0) {
		// TODO Auto-generated method stub
		return this.toString().compareTo(arg0.toString());
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append(new String(key));
		builder.append(":");
		builder.append(new String(columF));
		builder.append(":");
		builder.append(new String(columQ));
		return builder.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Arrays.hashCode(columF);
		result = prime * result + Arrays.hashCode(columQ);
		result = prime * result + Arrays.hashCode(key);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Model other = (Model) obj;
		if (!Arrays.equals(columF, other.columF))
			return false;
		if (!Arrays.equals(columQ, other.columQ))
			return false;
		if (!Arrays.equals(key, other.key))
			return false;
		return true;
	}
}
